package com.cmc.cloud.cmclink.doc.api.document;

import com.cmc.cloud.cmclink.doc.api.document.rep.VoyageBookingTimeRespDto;
import com.cmc.cloud.cmclink.doc.api.document.req.VoyageBookingTimeQueryDto;
import com.cmc.cloud.cmclink.doc.convert.VoyageBookingTimeConvert;
import com.cmc.cloud.cmclink.doc.entity.VoyageBookingTimeDO;
import com.cmc.cloud.cmclink.doc.mapper.VoyageBookingTimeMapper;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.mybatis.core.query.LambdaQueryWrapperX;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author lzp
 */
@RestController
@Validated
public class VoyageBookingTimeApiImpl implements VoyageBookingTimeApi {

    @Resource
    private VoyageBookingTimeMapper voyageBookingTimeMapper;

    @Override
    public CommonResult<List<VoyageBookingTimeRespDto>> queryVoyageBookingTime(VoyageBookingTimeQueryDto voyageBookingTimeQueryDto) {
        LambdaQueryWrapperX<VoyageBookingTimeDO> lambdaQueryWrapperX = new LambdaQueryWrapperX<>();
        lambdaQueryWrapperX.inIfPresent(VoyageBookingTimeDO::getVesselCode, voyageBookingTimeQueryDto.getVesselCodeS())
                .inIfPresent(VoyageBookingTimeDO::getVoyage, voyageBookingTimeQueryDto.getVoyageS())
                .eqIfPresent(VoyageBookingTimeDO::getExImType, voyageBookingTimeQueryDto.getExImType())
                .inIfPresent(VoyageBookingTimeDO::getPodCode, voyageBookingTimeQueryDto.getPodCodeS());
        List<VoyageBookingTimeDO> voyageBookingTimeDOList = voyageBookingTimeMapper.selectList(lambdaQueryWrapperX);
        if (CollectionUtils.isEmpty(voyageBookingTimeDOList)) {
            return CommonResult.success(Collections.emptyList());
        }
        List<VoyageBookingTimeRespDto> voyageBookingTimeRespDtoList = new ArrayList<>();
        voyageBookingTimeRespDtoList = VoyageBookingTimeConvert.INSTANCE.convertList(voyageBookingTimeDOList);
        return CommonResult.success(voyageBookingTimeRespDtoList);
    }
}
